package com.cucn.ingmall.order.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要的数据
 *
 * @author KouChaoJie
 * @since: 2022/1/19 10:28
 */
@ToString
public class OrderConfirmVO {
    /**
     * 用户收货地址列表
     */
    private List<MemberAddressVO> address;
    /**
     * 所有选中的购物项
     */
    private List<OrderItemVO> items;
    /**
     * 优惠信息(用户积分)
     */
    private Integer integration;
    /**
     * 唯一令牌防重复提交
     */
    private String orderToken;
    /**
     * 商品是否有库存?
     */
    @Getter
    @Setter
    private Map<Long, Boolean> stocks;

    /**
     * 订单总价格
     */
//    private BigDecimal total;

    /**
     * 应付价格
     */
    //private BigDecimal payPrice;
    public List<MemberAddressVO> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVO> address) {
        this.address = address;
    }

    public List<OrderItemVO> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVO> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    /**
     * 获取订单总价
     *
     * @return
     */
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /**
     * 应付价格
     *
     * @return
     */
    public BigDecimal getPayPrice() {
        return getTotal();
    }

    /**
     * 商品总数量
     */
    public Integer getCount() {
        Integer i = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVO item : items) {
                i = i + item.getCount();
            }
        }
        return i;
    }

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }
}
